package cn.config;

import cn.dao.ScopeBean;
import cn.domain.Clazz;
import cn.domain.Stu;
import com.zaxxer.hikari.HikariDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

import javax.sql.DataSource;

@Configuration
@ComponentScan("cn")
public class JavaConfig {
  @Bean({"jee-stu","haut-stu"})
  public Stu stu(){
    Stu stu=new Stu("zhang",21);
    return stu;
  }
  @Bean
  public Clazz clazz(){
    Clazz clazz=new Clazz();
    clazz.setName("se");
    clazz.setStu(stu());
    return clazz;
  }
  @Bean
  public DataSource dataSource(){
    HikariDataSource dataSource=new HikariDataSource();
    dataSource.setDriverClassName("org.hsqldb.jdbc.JDBCDriver");
    dataSource.setJdbcUrl("jdbc:hsqldb:hsql://localhost/");
    dataSource.setUsername("sa");
    dataSource.setPassword("");
    return dataSource;
  }
  @Bean
  @Scope("prototype")
  public ScopeBean scopeBean(){
    return new ScopeBean();
  }
}
